package barcode

import (
	"beergo/lib/tool"
	"github.com/boombuler/barcode"
	"github.com/boombuler/barcode/code128"
	"image/png"
	"os"
	"strings"
)

func CreateBar(str string) string {
	root := tool.AppRoot()
	bc, _ := code128.Encode(str)
	bar, _ := barcode.Scale(bc, 100, 50)
	file, _ := os.CreateTemp(root+"/static/var/barcode", "barcode_tmp*.png")
	defer file.Close()
	png.Encode(file, bar)
	//jpeg.Encode(file,bar,nil)
	fileName := file.Name()
	filePath := fileName[len(root):]
	filePath = strings.ReplaceAll(filePath, "\\", "/")
	return filePath
}
